<template>
    <div class="top"> 
            <img src="../assets/小于号.png" @click="a">
            <div class="title">{{msg}}收货地址</div>
            <div class="add" @click="baocun(index)">保存</div>
    </div>
</template>

<script>
import {mapState,mapGetters,mapMutations} from 'vuex'
export default {
  name: 'addressTop',
  props: {
    msg: String
  },
  data(){
      return{

      }
  },
  computed:{
      ...mapState(['msg','address','address1']),
     // ...mapGetters(['changeName'])
  },
  created(){
    //    console.log(this.address1.address1),
    //                 console.log(this.address1),
    //                 console.log(this.address)
   
  },
  methods:{
        ...mapMutations(['address1','address']),
        baocun(index){
            if(this.msg=="新建"){
                if(this.$store.state.address1[0].name===''||this.$store.state.address1[0].city===''||
                     this.$store.state.address1[0].phone===''||this.$store.state.address1[0].school===''||this.$store.state.address1[0].number==='')
                    {
                            alert("请填写完整！");
                    
                    }
                else{
                        this.address.push(this.address1[0])
                        this.$router.push({path:"/address"})
                }
            }
            if(this.msg=="编辑"){
                 if(this.$store.state.address1.address1.name===''||this.$store.state.address1.address1.city===''||
                     this.$store.state.address1.address1.phone===''||this.$store.state.address1.address1.school===''||this.$store.state.address1.address1.number==='')
                  {
                        alert("请填写完整！");
                
                  }
                  else{
                      this.$router.push({path:"/address"})
                  }
            }         
        },
        
        a(){
            this.$router.go(-1)
        }
  }
}
</script>

<style lang="scss" scoped>
    .top{
        display:flex;
        justify-content:space-between;
        padding: 3vw;
        background:white;
        margin-bottom: 3vw;
        .title{
            font-size: 5.5vw;
            font-weight: 350;
        }
        img{
            width: 6vw;
            height: 7vw;
            margin-top: 1vw;
        }
        .add{
            font-size: 4vw;
            margin-top: 1.5vw;
        }
    }
</style>